home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Tools & Apps / Networking & Communications / TCPTool / TCPReceive.c < prev    next >
Encoding:
Text File  |  1990-09-14  |  1.9 KB  |  81 lines  |  [TEXT/MPS ]

  1. //
  2. // MPW Tool by im.
  3. // Usage : TCPReceive
  4. // 
  5.  
  6. #include    <QuickDraw.h>
  7. #include    <Devices.h>
  8. #include    <stdio.h>
  9.  
  10. #include    <MacTCPCommonTypes.h>>
  11. #include    <AddressXlation.h>
  12. #include    <GetMyIPAddr.h>
  13. #include    <TCPPB.h>
  14. #include    <UDPPB.h>
  15.  
  16. #define        _STORAGE_    true
  17. #include    <TCP.h>
  18.  
  19.  
  20. main (int argc, char *argv[], char *envp[]) {
  21.     
  22.     auto    OSErr            osErr            = noErr;
  23.     auto    short            index;
  24.     auto    char            *option;
  25.     auto    char            *parameter;
  26.     auto    TCPNotifyProc    asrProc            = nil;
  27.     auto    TCPiopb            pb;
  28.     auto    StreamPtr        stream;
  29.     auto    char            streamBuf[4096];
  30.     auto    long            streamBufLen    = sizeof(streamBuf);
  31.     auto    Ptr                streamBufPtr;
  32.     auto    char            ioBuf[256]        = "";
  33.     auto    unsigned short    ioBufLen        = sizeof(ioBuf);
  34.     auto    ip_addr            localIP            = cAnyIP;
  35.     auto    ip_port            localPort        = cReceivePort;
  36.     auto    ip_addr            remoteIP        = cAnyIP;
  37.     auto    ip_port            remotePort        = cAnyPort;
  38.     
  39.     InitGraf((Ptr) &qd.thePort);
  40.  
  41.     index = 1;
  42.     while (index < argc) {
  43.     
  44.         option = argv[index++];
  45.         //parameter = argv[index++];
  46.         
  47.         if ('-' != option[0] || (! strchr("n", option[1])) || index > argc) {
  48.             printf("TCPReceive [-n]");
  49.             exit(1);
  50.         } else {
  51.             switch (option[1]) {
  52.                 case 'n' :
  53.                     asrProc = ASR;
  54.                     //index--;
  55.                     break;
  56.             }
  57.         }            
  58.     }
  59.     
  60.     osErr = _TCPInit();
  61.     if (noErr == osErr) {
  62.         osErr = _TCPCreate(&pb, &stream, streamBuf, streamBufLen, (TCPNotifyProc) asrProc, (Ptr) nil,  (TCPIOCompletionProc) nil, false);
  63.         if (noErr == osErr) {
  64.             osErr = _TCPPassiveOpen(&pb, stream, &remoteIP, &remotePort, &localIP, &localPort, (Ptr) nil, (TCPIOCompletionProc) nil, false);
  65.             if (noErr == osErr) {
  66.             
  67.                 /* receive data from the remote host */
  68.                 osErr = _TCPRcv(&pb, stream, ioBuf, &ioBufLen, (Ptr) nil, (TCPIOCompletionProc) nil, false);
  69.                 if (noErr == osErr)
  70.                     printf("%s\n", ioBuf);
  71.                 
  72.                 osErr = _TCPClose(&pb, stream, nil, (TCPIOCompletionProc) nil, false);
  73.             }
  74.             osErr = _TCPRelease(&pb, stream, &streamBufPtr, &streamBufLen, (TCPIOCompletionProc) nil, false);
  75.         }
  76.     }
  77.         
  78.     exit(osErr);
  79. }
  80.  
  81.